﻿#region Licence
//The MIT License (MIT)
//Copyright (c) 2014 abdallah HACID, https://www.facebook.com/ab.hacid

//Permission is hereby granted, free of charge, to any person obtaining a copy of this software
//and associated documentation files (the "Software"), to deal in the Software without restriction,
//including without limitation the rights to use, copy, modify, merge, publish, distribute,
//sublicense, and/or sell copies of the Software, and to permit persons to whom the Software
//is furnished to do so, subject to the following conditions:

//The above copyright notice and this permission notice shall be included in all copies or
//substantial portions of the Software.

//THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
//BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
//NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
//DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
//OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

// Project Hosting for Open Source Software on Codeplex : https://calgobots.codeplex.com/
#endregion

using System;
using System.Collections.Generic;
using cAlgo.API.Internals;
using cAlgo.API;

namespace cAlgo.Lib
{
	/// <summary>
	/// Extensions metho of type cAlgo.API.Position
	/// </summary>
	public static class ChartObjectsExtensions
	{

		private static string upArrow = "▲";
		private static string downArrow = "▼";
		private static string diamond = "♦";
		private static string bullet = "●";
		private static string stop = "x";

		private static Dictionary<string, Colors> arrowColors = new Dictionary<string, Colors>() { {upArrow,Colors.Green},{downArrow,Colors.Red},{diamond,Colors.MistyRose},{bullet,Colors.Navy},{stop,Colors.Red}};

		/// <summary>
		/// Draw arrow on the chart window
		/// </summary>
		/// <param name="chartObjects"></param>
		public static void drawArrow(this ChartObjects chartObjects, string arrow, int index, double? y=null, MarketSeries marketSeries=null, Symbol symbol=null)
		{
			if (marketSeries==null && ( index <0 || index > marketSeries.Close.Count-1))
				throw new ArgumentException(string.Format("Valeur de l'index {0} en dehors des valeurs permises", index));

			if (!y.HasValue)
				y = marketSeries.High[index] + 5 * symbol.PipSize;

			chartObjects.DrawText(arrow + index, arrow, index, y.Value, VerticalAlignment.Top, HorizontalAlignment.Center, arrowColors[arrow]);
		}

		/// <summary>
		/// Draw a up arrow on the chart window
		/// </summary>
		/// <param name="chartObjects"></param>
		public static void drawUpArrow(this ChartObjects chartObjects, int index, double? y=null, MarketSeries marketSeries=null, Symbol symbol=null)
		{
			chartObjects.drawArrow(upArrow,index,y,marketSeries,symbol);
		}

		/// <summary>
		/// Draw a down arrow on the chart window
		/// </summary>
		/// <param name="chartObjects"></param>
		public static void drawDnArrow(this ChartObjects chartObjects, int index, double? y=null, MarketSeries marketSeries=null, Symbol symbol=null)
		{
			chartObjects.drawArrow(downArrow, index, y, marketSeries, symbol);
		}

		/// <summary>
		/// Draw a diamond arrow on the chart window
		/// </summary>
		/// <param name="chartObjects"></param>
		public static void drawDiamondArrow(this ChartObjects chartObjects, int index, double? y=null, MarketSeries marketSeries=null, Symbol symbol=null)
		{
			chartObjects.drawArrow(diamond,index,y,marketSeries,symbol);
		}

		/// <summary>
		/// Draw a bullet arrow on the chart window
		/// </summary>
		/// <param name="chartObjects"></param>
		public static void drawBulletArrow(this ChartObjects chartObjects, int index, double? y=null, MarketSeries marketSeries=null, Symbol symbol=null)
		{
			chartObjects.drawArrow(bullet, index, y, marketSeries, symbol);
		}

		/// <summary>
		/// Draw a stop arrow on the chart window
		/// </summary>
		/// <param name="chartObjects"></param>
		public static void drawStopArrow(this ChartObjects chartObjects, int index, double? y=null, MarketSeries marketSeries=null, Symbol symbol=null)
		{
			chartObjects.drawArrow(stop, index, y, marketSeries, symbol);
		}
	}
}
